<?php
/**
 * Description of picture of the album record
 *
 * @author Lukas Normantas
 */
class Content_Model_Picture extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('catalog_pictures');
        $this->hasColumn('album_id', 'integer');
        $this->hasColumn('filename', 'string', 255);
        $this->hasColumn('position', 'integer', 11, array('notnull'=>false));
    }

    public function setPosition($p)
    {
        $this->position = $p;
        return true;
    }

    public function setUp()
    {
        $this->actAs('Timestampable');

        $sortable = new Areal_Doctrine_Template_Sortable(array('uniqueBy'=>array('album_id')));
        $this->actAs($sortable);

        $this->hasOne('Content_Model_Album as Album', array(
            'local' => 'album_id',
            'foreign' => 'id'
        ));
    }

    static public function getThumb($picture_id)
    {
        $content = Areal_Image::getThumbContent(DATA_PATH
                                                . 'content_pictures/picture-'.$picture_id.'.jpg');
        return $content;
    }


    static public function getImage($picture_id)
    {
        $content = Areal_Image::getImageContent(DATA_PATH
                                                . 'content_pictures/picture-'.$picture_id.'.jpg');
        return $content;
    }

    public function delete(){
        unlink(DATA_PATH . 'content_pictures/picture-'.$this->id.'.jpg');
        parent::delete();
    }

}